<template>
  <el-row :gutter="20">
    <el-col :sm="2" class="hidden-xs-only" style="opacity:0;">左侧占位</el-col>
    <el-col :xs="24" :sm="20">
      <el-card style="background-color: rgba(255,255,255,0.9)" class="gallery-card">
        <div slot="header" class="total">
          <div class="titleIndex">
            <i class="el-icon-picture"></i>
            <span>照片墙</span>
          </div>
        </div>
        <div class="gallery-container">
          <div class="gallery-filter">
            <el-radio-group v-model="filterCategory" @change="handleFilterChange">
              <el-radio-button label="all">全部</el-radio-button>
              <el-radio-button label="nature">自然风光</el-radio-button>
              <el-radio-button label="city">城市建筑</el-radio-button>
              <el-radio-button label="life">生活日常</el-radio-button>
              <el-radio-button label="tech">技术相关</el-radio-button>
            </el-radio-group>
          </div>
          <div class="gallery-grid">
            <div 
              v-for="photo in filteredPhotos" 
              :key="photo.id"
              class="gallery-item"
              @click="viewPhoto(photo)"
            >
              <el-image
                :src="photo.url"
                :alt="photo.title"
                fit="cover"
                lazy
                class="gallery-image"
              >
                <div slot="error" class="image-slot">
                  <i class="el-icon-picture-outline"></i>
                </div>
              </el-image>
              <div class="gallery-overlay">
                <div class="gallery-info">
                  <h4>{{ photo.title }}</h4>
                  <p>{{ photo.description }}</p>
                  <span class="gallery-date">{{ photo.date }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-card>
      
      <!-- 图片预览对话框 -->
      <el-dialog
        :visible.sync="dialogVisible"
        :fullscreen="false"
        width="80%"
        class="photo-dialog"
      >
        <div class="photo-viewer" v-if="currentPhoto">
          <el-image
            :src="currentPhoto.url"
            :alt="currentPhoto.title"
            fit="contain"
            class="viewer-image"
          ></el-image>
          <div class="viewer-info">
            <h3>{{ currentPhoto.title }}</h3>
            <p>{{ currentPhoto.description }}</p>
            <div class="viewer-meta">
              <el-tag size="small" type="info">{{ currentPhoto.category }}</el-tag>
              <span class="viewer-date">{{ currentPhoto.date }}</span>
            </div>
          </div>
        </div>
      </el-dialog>
    </el-col>
    <el-col :sm="2" class="hidden-xs-only" style="opacity:0;">右侧占位</el-col>
  </el-row>
</template>

<script>
export default {
  name: 'Gallery',
  data() {
    return {
      filterCategory: 'all',
      dialogVisible: false,
      currentPhoto: null,
      photoList: [
        {
          id: 1,
          title: '自然风光',
          description: '美丽的自然景色',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-12-15',
          category: 'nature'
        },
        {
          id: 2,
          title: '城市建筑',
          description: '现代城市建筑',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-12-10',
          category: 'city'
        },
        {
          id: 3,
          title: '生活日常',
          description: '日常生活瞬间',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-12-05',
          category: 'life'
        },
        {
          id: 4,
          title: '技术相关',
          description: '编程开发环境',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-11-28',
          category: 'tech'
        },
        {
          id: 5,
          title: '自然风光2',
          description: '山景如画',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-11-20',
          category: 'nature'
        },
        {
          id: 6,
          title: '城市夜景',
          description: '灯火辉煌的城市',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-11-15',
          category: 'city'
        },
        {
          id: 7,
          title: '工作日常',
          description: '办公环境',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-11-10',
          category: 'life'
        },
        {
          id: 8,
          title: '代码截图',
          description: '项目代码',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-11-05',
          category: 'tech'
        },
        {
          id: 9,
          title: '海滩风光',
          description: '美丽的海滩',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-10-30',
          category: 'nature'
        },
        {
          id: 10,
          title: '现代建筑',
          description: '建筑设计',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-10-25',
          category: 'city'
        },
        {
          id: 11,
          title: '美食分享',
          description: '美食照片',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-10-20',
          category: 'life'
        },
        {
          id: 12,
          title: '开发工具',
          description: 'IDE界面',
          url: 'https://via.placeholder.com/400x300',
          date: '2024-10-15',
          category: 'tech'
        }
      ]
    }
  },
  computed: {
    filteredPhotos() {
      if (this.filterCategory === 'all') {
        return this.photoList
      }
      return this.photoList.filter(photo => photo.category === this.filterCategory)
    }
  },
  methods: {
    handleFilterChange() {
      // 过滤逻辑已在computed中处理
    },
    viewPhoto(photo) {
      this.currentPhoto = photo
      this.dialogVisible = true
    }
  }
}
</script>

<style scoped>
.gallery-card {
  margin-top: 20px;
}

.titleIndex {
  display: flex;
  align-items: center;
  font-size: larger;
  font-weight: bold;
}

.titleIndex i {
  margin-right: 10px;
  color: #409eff;
  font-size: 20px;
}

.gallery-container {
  padding: 20px 0;
}

.gallery-filter {
  margin-bottom: 30px;
  text-align: center;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  padding: 20px 0;
}

.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  cursor: pointer;
  aspect-ratio: 4/3;
  transition: all 0.3s;
}

.gallery-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.gallery-image {
  width: 100%;
  height: 100%;
  transition: transform 0.3s;
}

.gallery-item:hover .gallery-image {
  transform: scale(1.1);
}

.gallery-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  opacity: 0;
  transition: opacity 0.3s;
  display: flex;
  align-items: flex-end;
  padding: 15px;
}

.gallery-item:hover .gallery-overlay {
  opacity: 1;
}

.gallery-info {
  color: #fff;
  width: 100%;
}

.gallery-info h4 {
  margin: 0 0 5px 0;
  font-size: 16px;
}

.gallery-info p {
  margin: 0 0 5px 0;
  font-size: 13px;
  opacity: 0.9;
}

.gallery-date {
  font-size: 12px;
  opacity: 0.8;
}

.image-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background: #f5f7fa;
  color: #909399;
  font-size: 30px;
}

.photo-viewer {
  text-align: center;
}

.viewer-image {
  width: 100%;
  max-height: 60vh;
  margin-bottom: 20px;
}

.viewer-info {
  text-align: left;
  padding: 20px;
  background-color: #f5f7fa;
  border-radius: 4px;
}

.viewer-info h3 {
  margin: 0 0 10px 0;
  color: #303133;
}

.viewer-info p {
  color: #606266;
  line-height: 1.6;
  margin-bottom: 15px;
}

.viewer-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.viewer-date {
  color: #909399;
  font-size: 14px;
}

@media screen and (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }
  
  .gallery-filter {
    margin-bottom: 20px;
  }
  
  .gallery-filter .el-radio-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .gallery-filter .el-radio-button {
    margin: 5px;
  }
}
</style>

